package com.hbnu.system.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hbnu.system.config.BaseException;
import com.hbnu.system.mapper.CooperaFormMapper;
import com.hbnu.system.model.entity.CooperaForm;
import com.hbnu.system.service.CooperaFormService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

@Service
public class CooperaFormServiceImpl extends ServiceImpl<CooperaFormMapper, CooperaForm> implements CooperaFormService {
    @Override
    public boolean addCooperaForm(CooperaForm cooperaForm) {
        CooperaForm cooperaForm1 = super.getOne(Wrappers.lambdaQuery(CooperaForm.class)
                .eq(CooperaForm::getCooperaFormName,cooperaForm.getCooperaFormName()));
        if(StrUtil.isEmpty(cooperaForm.getCooperaFormName())||StrUtil.isBlank(cooperaForm.getCooperaFormName())){
            throw new BaseException("该合作形式名称为空");
        }
        if(!Objects.isNull(cooperaForm1)){
            throw new BaseException("该合作形式名称已存在");
        }
        return baseMapper.insert(cooperaForm)==1;
    }

    @Override
    public List<CooperaForm> getCooperaFormList() {
        List<CooperaForm> depts = baseMapper.selectList(Wrappers.lambdaQuery(CooperaForm.class));
//        List<String> result = new ArrayList<>();
//        for (Dept dept : depts) {
//            result.add(dept.getDeptName());
//        }
        return depts;
    }

    @Override
    public boolean updateCooperaForm(CooperaForm projectcate) {
        return false;
    }

    @Override
    public boolean deleteCooperaForm(String ID) {
        return baseMapper.deleteById(ID) == 1;
    }
}
